﻿using Microsoft.Extensions.DependencyInjection;

namespace ApplicationBase.Core.Utils
{
    public static class SnowflakeServiceCollectionExtensions
    {
        public static IServiceCollection AddSnowflakeWorker(this IServiceCollection services)
            => services.AddSnowflakeWorker(options => { });

        public static IServiceCollection AddSnowflakeWorker(this IServiceCollection services, Action<SnowflakeOptions> setupAction)
        {
            if(setupAction != null)
            {
                services.Configure(setupAction);
            }

            services.AddSingleton<IClock, UTCClock>();
            services.AddSingleton<ISnowflakeWorker, SnowflakeWorker>();
            return services;
        }
    }
}
